package com.example.javamaday.leetcode;

import com.example.javamaday.leetcode.base.TreeNode;
import com.example.javamaday.leetcode.base.TreeStrNode;

import java.util.ArrayList;
import java.util.List;

public class LeetCodeTest0257 {

    private final ArrayList<String> result = new ArrayList<>();

    public static void main(String[] args) {

    }

    public List<String> binaryTreePaths(TreeNode root) {
        if (root == null) {
            return new ArrayList<>();
        }
        TreeStrNode sumRoot = new TreeStrNode(root.val + "");
        scanTree(root, sumRoot);
        return result;
    }

    private void scanTree(TreeNode root, TreeStrNode sumRoot) {
        if (root.left == null && root.right == null) {
            result.add(sumRoot.val);
            return;
        }
        if (root.left != null) {
            sumRoot.left = new TreeStrNode(sumRoot.val + "->" + root.left.val);
            scanTree(root.left, sumRoot.left);
        }
        if (root.right != null) {
            sumRoot.right = new TreeStrNode(sumRoot.val + "->" + root.right.val);
            scanTree(root.right, sumRoot.right);
        }
    }
}
